package com.glory.cqaospda.adapter;


import android.graphics.Color;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.glory.cqaospda.R;
import com.glory.cqaospda.bean.EqpMaterialsBean;
import com.glory.cqaospda.bean.LotInfoBean;

import java.util.List;

import androidx.annotation.Nullable;

public class MateriaAdapter extends BaseQuickAdapter<EqpMaterialsBean.Materialslist, BaseViewHolder> {
    private List<EqpMaterialsBean.Materialslist> datalist;
    private String type;
    private OnItemClickListener mOnItemClickListener;

    public MateriaAdapter(@Nullable List<EqpMaterialsBean.Materialslist> data, String type) {
        super(R.layout.adapter_carriertape, data);
        datalist = data;
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, EqpMaterialsBean.Materialslist item) {
        helper.setText(R.id.tvCarriertapeID, item.getMMaterialId());
        helper.setText(R.id.tvCarriertapeQty, item.getMMaterialQty());
        helper.setText(R.id.tvMaterialUnit, item.getMMaterialUnit());
        helper.setText(R.id.tvVendorCode, item.getMVendorCode());
        helper.setText(R.id.tvLotID, item.getMMateriallotId());
        helper.getView(R.id.llMateria).setOnClickListener(view -> {
            mOnItemClickListener.onItemClick(item);
        });
        switch (type){
            case "carriertapeData":
                helper.setText(R.id.tvType, "载带");
                if (!item.isReplace()) {
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#2E9AFE"));
                }else{
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#ff9b00"));
                }
//                helper.setTextColor(R.id.tvCarriertapeID, Color.parseColor("#FF0000"));
                break;
            case "reelData":
                helper.setText(R.id.tvType, "卷盘");
                if (!item.isReplace()) {
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#A9E2F3"));
                }else{
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#ff9b00"));
                }
//              helper.setTextColor(R.id.tvCarriertapeID, Color.parseColor("#FF8000"));
                break;
            case "coverData":
                helper.setText(R.id.tvType, "料管");
                if (!item.isReplace()) {
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#2E9AFE"));
                }else{
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#ff9b00"));
                }
//                helper.setTextColor(R.id.tvCarriertapeID, Color.parseColor("#FFFF00"));
                break;
            case "plugData":
                helper.setText(R.id.tvType, "盖带");
                if (!item.isReplace()) {
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#A9E2F3"));
                }else{
                    helper.setBackgroundColor(R.id.llMateria, Color.parseColor("#ff9b00"));
                }
//                helper.setTextColor(R.id.tvCarriertapeID, Color.parseColor("#3ADF00"));
                break;
        }
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(EqpMaterialsBean.Materialslist data);
    }

}
